package com.lwj.controller.system;

import com.lwj.dto.system.CategoryListDto;
import com.lwj.dto.system.DefListDto;
import com.lwj.dto.system.DictionaryCategoryDto;
import com.lwj.dto.system.DictionaryDefDto;
import com.lwj.entity.RestEntity;
import com.lwj.model.system.DictionaryDef;
import com.lwj.service.system.DictionaryCategoryService;
import com.lwj.service.system.DictionaryDefService;
import com.lwj.vo.PageBean;
import com.lwj.vo.system.DictionaryCategoryVo;
import com.lwj.vo.system.DictionaryDefVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags ="字典接口")
@RestController()
@RequestMapping("/api/dictionary")
public class DictionaryController {
    @Autowired
    private DictionaryCategoryService dictionaryCategoryService;
    @Autowired
    private DictionaryDefService dictionaryDefService;
    @ApiOperation(value = "字典分类列表")
    @GetMapping("/category/list")
    public RestEntity<PageBean<DictionaryCategoryVo>> categoryList(CategoryListDto dto){
        return RestEntity.success(dictionaryCategoryService.categoryList(dto));
    }
    @ApiOperation(value = "字典分类编辑")
    @PostMapping("/category/update")
    public RestEntity<Integer> updateCategory(@RequestBody DictionaryCategoryDto dto){
        return RestEntity.success(dictionaryCategoryService.updateCategory(dto));
    }
    @ApiOperation(value = "字典值列表")
    @GetMapping("/def/list")
    public RestEntity<PageBean<DictionaryDefVo>> defList(DefListDto dto){
        return RestEntity.success(dictionaryDefService.defList(dto));
    }
    @ApiOperation(value = "字典值编辑")
    @PostMapping("/def/save")
    public RestEntity<Integer> saveDef(@RequestBody DictionaryDefDto dto){
        return RestEntity.success(dictionaryDefService.saveDef(dto));
    }
    @ApiOperation(value = "字典值列表")
    @GetMapping("/def/getByCategoryId")
    public RestEntity<List<DictionaryDefVo>> getByCategoryId(@RequestParam("categoryId") String categoryId){
        return RestEntity.success(dictionaryDefService.getByCategoryId(categoryId));
    }
    @ApiOperation(value = "根据分类code获取字典值")
    @GetMapping("/def/getByCategoryCode")
    public RestEntity<List<DictionaryDefVo>> getByCategoryCode(@RequestParam("categoryCode") String categoryCode){
        return RestEntity.success(dictionaryDefService.getByCategoryCode(categoryCode));
    }
}
